package com.friend.joey.applicationfriend;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v7.app.NotificationCompat;

import com.friend.joey.applicationfriend.R;

import static com.baidu.location.h.j.l;

/**
 * Created by Joey on 2017/5/30.
 */

public class AlarmService extends Service {

    private NotificationManager manager;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//        NotificationManager manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//        Notification notification=new NotificationCompat.Builder(this)
//                .setContentTitle("OldFriend")
//                .setContentText("2")
//                .setWhen(System.currentTimeMillis())
//                .setSmallIcon(R.mipmap.ic_launcher)
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
//                .build();
//        startForeground(5,notification);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        int time=intent.getIntExtra("time",0);
        String title=intent.getStringExtra("title");
        String content=intent.getStringExtra("content");
        NotificationManager manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification=new NotificationCompat.Builder(this)
                .setContentTitle(title)
                .setContentText(content)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .build();
        notification.flags=Notification.FLAG_INSISTENT;
        manager.notify(time,notification);
        stopSelf();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        getMyNotification(3,"提醒服务关闭");
    }
    public void getMyNotification(int i,String s){
        Notification notification=new NotificationCompat.Builder(this)
                .setContentTitle("OldFriend轨迹")
                .setContentText(s)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .build();
        manager.notify(i,notification);
    }
}
